<!doctype html>



  


<html class="theme-next mist use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/vendors/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Java,多线程," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.0.1" />






<meta name="description" content="说明：Java 多线程：notify、Executor框架、Fork/Join 框架、Lock/Condition。">
<meta name="keywords" content="Java,多线程">
<meta property="og:type" content="article">
<meta property="og:title" content="Java 多线程">
<meta property="og:url" content="http://bebetter.site/2017/09/01/Language/Java-concurrency/Java 多线程/index.html">
<meta property="og:site_name" content="gatewayzy">
<meta property="og:description" content="说明：Java 多线程：notify、Executor框架、Fork/Join 框架、Lock/Condition。">
<meta property="og:updated_time" content="2017-09-01T05:58:10.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Java 多线程">
<meta name="twitter:description" content="说明：Java 多线程：notify、Executor框架、Fork/Join 框架、Lock/Condition。">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Mist',
    sidebar: {"position":"right","display":"always"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: 0,
      author: '博主'
    }
  };
</script>




  <link rel="canonical" href="http://bebetter.site/2017/09/01/Language/Java-concurrency/Java 多线程/"/>

  <title> Java 多线程 | gatewayzy </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  










  
  
    
  

  <div class="container one-collumn sidebar-position-right page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">gatewayzy</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">blog of gatewayzy</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                Java 多线程
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2017-09-01T13:58:10+08:00" content="2017-09-01">
              2017-09-01
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/Language/" itemprop="url" rel="index">
                    <span itemprop="name">Language</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p><strong>说明：</strong>Java 多线程：notify、Executor框架、Fork/Join 框架、Lock/Condition。<br><a id="more"></a></p>
<p>参考文章：《Java 并发编程实战》</p>
<h2 id="多线程基础：Thread接口-Runnable接口"><a href="#多线程基础：Thread接口-Runnable接口" class="headerlink" title="多线程基础：Thread接口 Runnable接口"></a>多线程基础：Thread接口 Runnable接口</h2><hr>
<ul>
<li>线程属性：id、name、priority、status，使用对应的getter和setter方法。</li>
<li>线程状态6种 status：new、runnable、blocked、waiting、time waiting、terminated</li>
<li>run()只是在当前线程执行程序，并不会启动新的线程，start()才能启动新的线程。</li>
<li>继承Thread类，重写run方法：class MyThread extends Thread{ public void run(){ }} 然后new MyThread().start(); 启动线程。</li>
<li>实现Runnable接口，实现run方法：class MyRun implements Runnable{ public void run(){ }}，然后MyRun myrun = new MyRun();new Thread(myrun).start(); 如果使用多个new Thread(myrun).start() 访问的是同一个my对象，需要考虑并发安全问题。</li>
<li>thread1.setDaemon(true); // 将该线程设置为守护线程，一旦主线程运行结束，daemon线程自动退出。守护线程不要涉及业务、资源，可以用于定时退出(主线程定时结束，自己也就自动结束)等，使用t1.isDaemon()判断是不是守护线程。</li>
<li>主线程调用t1.interrupt()设置t1的中断标志为true，t1会抛出InterruptedException。</li>
<li>isInterrupted() interrupted()二者都可以检测线程是否是被中断，不同在于：interrupted()是一个static方法，并会将中断标志置为true，isInterrupted()只是检测中断标志。</li>
<li>主线程调用t1.sleep(1000)让线程t1休眠1s，也可以使用TimeUnit.SECONDS.sleep(1)调用方式。</li>
<li>主线程调用t1.yield()会让t1让步，其他线程先执行，但jvm并不一定会遵守此策略，一般只用于调试。</li>
<li>主线程调用t2.join()会让t2先执行，挂起自己，等待t2执行完成才执行自己，t2.join(100)还会限定t2只有100毫秒的运行时间。</li>
<li>线程的local copy与对数据的master copy：多个线程共享方法代码、参数等，每个线程都有堆数据(master copy)的local copy版本。如果线程进行++操作，++不是原子性操作，会分为读取(读取local copy)，自增(使用local copy+1)，赋值(flush到master)步骤，可能出现如下问题：<ul>
<li>如果多线程的++不进行控制，读写都是随意并行的：一个线程++完到自己的local copy，但是还没来得及flush到mater copy，就会出现线程拷贝与主拷贝不一致，另一个线程B也在++，而且读的是A在flush之前的数据，两个都flush到master可能多线程会写覆盖。</li>
<li>如果使用volatile数据，一个线程A在++写完local copy之后，会确保master是正确的，但是如果另一个线程B要读数据，会从master copy读数据，这没问题，但是如果B之前已经读了数据，准备写数据，就会发生master被覆盖，发生写丢失。</li>
<li>如果使用synchronized数据，线程A的整个++过程都是在同步代码块中，已经获得对象锁或类锁，其他线程无法进行++操作，所以master copy和各个local copy之间不会发生读写丢失，保证了线程安全。</li>
</ul>
</li>
<li>线程局部变量： 一个Runnable接口中定义 <code>static ThreadLocal&lt;String&gt; s = new ThreadLocal&lt;&gt;(){protected String initialValue(){return &quot;&quot;;}};</code> 这种线程局部变量只会被各个线程独立拥有，使用的时候使用<code>s.get();s.set(&quot;1&quot;)</code>remove等方法操作线程局部变量。</li>
<li>线程分组</li>
<li>线程工厂接口：ThreadFactory接口，属于工厂模式、创建模式。需要实现其Thread newThread(Runnable r)方法，常见就是直接返回自定义的Runnable实现类。</li>
</ul>
<h2 id="sychronized-关键字-基本同步机制"><a href="#sychronized-关键字-基本同步机制" class="headerlink" title="sychronized 关键字 基本同步机制"></a>sychronized 关键字 基本同步机制</h2><hr>
<ul>
<li>synchronized 关键字，使用 wait notify等待和同步。</li>
<li>互斥同步机制应该尽量轻量级，锁的范围越小越好：<ul>
<li>能不用锁就不用锁，比如用并发的数据结构实现业务</li>
<li>能用对象级别锁就不要用类级别锁</li>
<li>锁的范围越小越好，比如同步方法最好缩小到同步代码块</li>
</ul>
</li>
</ul>
<h2 id="Lock-Condition-基本同步机制"><a href="#Lock-Condition-基本同步机制" class="headerlink" title="Lock/Condition 基本同步机制"></a>Lock/Condition 基本同步机制</h2><hr>
<ul>
<li>Lock接口，常见的实现类有 ReentrantLock、ReentrantReadWriteLock.ReadLock/WriteLock。</li>
</ul>
<h2 id="高级同步机制"><a href="#高级同步机制" class="headerlink" title="高级同步机制"></a>高级同步机制</h2><hr>
<h3 id="Semaphore-信号量同步机制"><a href="#Semaphore-信号量同步机制" class="headerlink" title="Semaphore 信号量同步机制"></a>Semaphore 信号量同步机制</h3><ul>
<li>Semaphore信号量进行acquire() release()。</li>
</ul>
<h3 id="CountDownLatch-同步辅助类"><a href="#CountDownLatch-同步辅助类" class="headerlink" title="CountDownLatch 同步辅助类"></a>CountDownLatch 同步辅助类</h3><ul>
<li>CountDownLatch 一种同步辅助类jdk1.7，让当前线程await()其他操作。初始化数值作为计数器，监听await()事件（会在cd结束的时候收到异常通知），继续运行。</li>
</ul>
<h3 id="CyclicBarrier-同步辅助类"><a href="#CyclicBarrier-同步辅助类" class="headerlink" title="CyclicBarrier 同步辅助类"></a>CyclicBarrier 同步辅助类</h3><ul>
<li>CyclicBarrier 一种同步辅助类，允许多个线程在一个集合点相互等待。</li>
</ul>
<h3 id="Phaser-同步辅助类"><a href="#Phaser-同步辅助类" class="headerlink" title="Phaser 同步辅助类"></a>Phaser 同步辅助类</h3><ul>
<li>Phaser 一种同步辅助类，适合具有多个步骤的并发任务。在每个阶段结束时，同步等待其他线程，因此，只有所有线程都执行完各自的第一个步骤，才会开始第二个步骤的任务。arrive()。</li>
</ul>
<h3 id="Exchanger-同步辅助类"><a href="#Exchanger-同步辅助类" class="headerlink" title="Exchanger 同步辅助类"></a>Exchanger 同步辅助类</h3><ul>
<li>Exchanger 一种同步辅助类，为两个线程提供数据交换点。</li>
</ul>
<h2 id="Executor-Framework-执行器框架-Callable接口"><a href="#Executor-Framework-执行器框架-Callable接口" class="headerlink" title="Executor Framework 执行器框架  Callable接口"></a>Executor Framework 执行器框架  Callable接口</h2><hr>
<ul>
<li>Executor 执行器框架将线程创建和执行分离。jdk1.5开始增加Executor框架。</li>
<li>Executor 框架基于Executor接口和ExecutorService接口，以及这两个接口的实现类ThreadPoolExecutor。</li>
<li>Executor有一个内部线程池，可以将任务传递到线程池并执行。传递的任务有下面两种。尝试调用线程池中的线程执行任务，而不是每次都新建和销毁线程，线程池提高了性能和效率。<ul>
<li>Runnable接口实现的任务，不会返回任务执行结果。</li>
<li>Callable接口实现的任务，将返回执行结果。</li>
</ul>
</li>
</ul>
<h3 id="Callable接口"><a href="#Callable接口" class="headerlink" title="Callable接口"></a>Callable接口</h3><hr>
<ul>
<li>Callable接口属于Executor框架，该接口类似于Runnable接口，但是有两点增强：<ul>
<li>接口需要实现方法call()，可以返回结果。</li>
<li>发送一个Callable对象给Executor时，会获得一个实现了Future接口的对象，该对象可以用于控制Callable对象的状态和结果。</li>
</ul>
</li>
</ul>
<h2 id="Fork-Join-Framework-分解-合并框架"><a href="#Fork-Join-Framework-分解-合并框架" class="headerlink" title="Fork/Join Framework 分解/合并框架"></a>Fork/Join Framework 分解/合并框架</h2><hr>
<ul>
<li>jdk7 增加了Fork/Join框架。ForkJoin Framework与Executor Framework的主要区别在于Work-Stealing Algorithm 工作窃取算法。</li>
<li>ForkJoin框架核心类是：<ul>
<li>ForkJoinPool： 实现了Executor接口和Work-Stealing Algorithm。用于管理工作者线程，提供任务的状态和执行信息。</li>
<li>ForkJoinTask：作为在ForkJoinPool中执行的基类。</li>
</ul>
</li>
<li>两种任务：RecursiveAction 适用于没有返回结果的任务，RecursiveTask 适用于有返回结果的任务。</li>
</ul>
<h2 id="并发集合"><a href="#并发集合" class="headerlink" title="并发集合"></a>并发集合</h2><hr>
<ul>
<li>并发类的集合也分为阻塞式和非阻塞式：<ul>
<li>阻塞式集合 Blocking Collection 集合已满或者为空时，进行添加或者删除操作时，会阻塞当前线程，直到方法可以被成功执行。</li>
<li>非阻塞式集合 Non-Blocking Collection 如果添加或删除方法不能被立即执行，会返回null或异常，方法所属线程不会阻塞。</li>
</ul>
</li>
<li>Java集合框架中的并发集合：<ul>
<li>非阻塞式列表 ConcurrentLinkedDeque 类</li>
<li>阻塞式列表 LinkedBlockingDeque 类</li>
<li>原子变量对应的实现类 AtomicLong和AtomicIntegerArray。可以自己继承AtomicLong实现原子类，利用父类的CAS原子性操作public final boolean compareAndSet(int expect, int update) 等方法。</li>
<li>……</li>
</ul>
</li>
</ul>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Java/" rel="tag">#Java</a>
          
            <a href="/tags/多线程/" rel="tag">#多线程</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/09/01/Algorithm/Java开发面试题/" rel="next" title="Java开发面试题">
                <i class="fa fa-chevron-left"></i> Java开发面试题
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/09/01/Language/Java-basic/Java 变量类型/" rel="prev" title="Java 变量类型">
                Java 变量类型 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    


  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/statics/images/avatar.png"
               alt="gatewayzy" />
          <p class="site-author-name" itemprop="name">gatewayzy</p>
          <p class="site-description motion-element" itemprop="description">blog website with hexo and github pages</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">70</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">10</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">38</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              友情链接
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="https://github.com/gatewayzy" title="Github-gatewayzy" target="_blank">Github-gatewayzy</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://google.com/" title="Goolge" target="_blank">Goolge</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://wiki.jikexueyuan.com/" title="Wiki-jike" target="_blank">Wiki-jike</a>
                </li>
              
            </ul>
          </div>
        

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">
            
              
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#多线程基础：Thread接口-Runnable接口"><span class="nav-number">1.</span> <span class="nav-text">多线程基础：Thread接口 Runnable接口</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#sychronized-关键字-基本同步机制"><span class="nav-number">2.</span> <span class="nav-text">sychronized 关键字 基本同步机制</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Lock-Condition-基本同步机制"><span class="nav-number">3.</span> <span class="nav-text">Lock/Condition 基本同步机制</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#高级同步机制"><span class="nav-number">4.</span> <span class="nav-text">高级同步机制</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#Semaphore-信号量同步机制"><span class="nav-number">4.1.</span> <span class="nav-text">Semaphore 信号量同步机制</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#CountDownLatch-同步辅助类"><span class="nav-number">4.2.</span> <span class="nav-text">CountDownLatch 同步辅助类</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#CyclicBarrier-同步辅助类"><span class="nav-number">4.3.</span> <span class="nav-text">CyclicBarrier 同步辅助类</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Phaser-同步辅助类"><span class="nav-number">4.4.</span> <span class="nav-text">Phaser 同步辅助类</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Exchanger-同步辅助类"><span class="nav-number">4.5.</span> <span class="nav-text">Exchanger 同步辅助类</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Executor-Framework-执行器框架-Callable接口"><span class="nav-number">5.</span> <span class="nav-text">Executor Framework 执行器框架  Callable接口</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#Callable接口"><span class="nav-number">5.1.</span> <span class="nav-text">Callable接口</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Fork-Join-Framework-分解-合并框架"><span class="nav-number">6.</span> <span class="nav-text">Fork/Join Framework 分解/合并框架</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#并发集合"><span class="nav-number">7.</span> <span class="nav-text">并发集合</span></a></li></ol></div>
            
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">gatewayzy</span>
</div>

<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>

        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/vendors/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/vendors/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/vendors/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.1"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.0.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.0.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.1"></script>



  



  




  
  

  
  <script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      tex2jax: {
        inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
        processEscapes: true,
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
    });
  </script>

  <script type="text/x-mathjax-config">
    MathJax.Hub.Queue(function() {
      var all = MathJax.Hub.getAllJax(), i;
      for (i=0; i < all.length; i += 1) {
        all[i].SourceElement().parentNode.className += ' has-jax';
      }
    });
  </script>
  <script type="text/javascript" src="//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>



  

  
<script type="text/javascript" async src="//push.zhanzhang.baidu.com/push.js">
</script>


</body>
</html>
